package com.hongye.third.controller;


import com.hongye.common.annotation.FiltrationResponse;
import com.hongye.common.utils.ResponseResult;
import com.hongye.third.utils.MsgUtil;
import com.hongye.third.utils.OssUtil;
import com.hongye.third.utils.OssUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.util.ArrayList;
import java.util.List;

/**
 * @author my
 * @email 2148852429@qq.com
 * @date 2022/4/19
 * @time 15:53
 */
@RestController
@RequestMapping("/hongye/third")
@Slf4j
public class FileController {

    @Autowired
    private OssUtil ossUtil;
    @Autowired
    private OssUtils ossUtils;

    @RequestMapping("/upload")
    @FiltrationResponse
    public ResponseResult<String> upload(MultipartFile file){
        ResponseResult<String> uploadFile = ossUtil.uploadFile(file);
        log.info("imageUrl={}",uploadFile.getData());
        return uploadFile;
    }


    @RequestMapping("/sendPhoneMsg")
    @FiltrationResponse
    public String  sendPhoneMsg(@RequestParam("phone") String phone){
        String code = MsgUtil.sendMsg(phone);
        return code;
    }


    @RequestMapping("/uploadArray")
    @FiltrationResponse
    public List<String> uploadArray(MultipartFile[] file){
        ArrayList<String> files = new ArrayList<>();
        for (MultipartFile multipartFile : file) {
            String uploadFile = ossUtils.uploadFile(multipartFile);
            files.add(uploadFile);
        }
        return files;
    }

}
